package org.jleaf.springcloud.user;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.jleaf.springcloud.user.model.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.concurrent.atomic.AtomicLong;

/**
 * 用户服务
 * <p>
 * Created by leaf on 2016/8/2 0002.
 */
@SpringBootApplication
@RestController
@EnableDiscoveryClient
@EnableSwagger2
@Api("用户服务")
public class UserApplication {

    private static Logger log = LoggerFactory.getLogger(UserApplication.class);

    private static AtomicLong atomicLong = new AtomicLong();

    @Value("${server.port}")
    private String serverPort;

    @RequestMapping("basicInfo")
    @ApiOperation("获取用户基本信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "id", dataType = "Long", required = true, value = "用户id", defaultValue = "1"),
            @ApiImplicitParam(paramType = "query", name = "status", dataType = "String", required = false, value = "用户状态")
    })
    @ApiResponses({
            @ApiResponse(code = 403, message = "权限错误"),
            @ApiResponse(code = 500, message = "服务器错误")
    })
    public Object basicInfo(Long id,String status) {
        long count = atomicLong.addAndGet(1);
        log.info("baseinfo:{}, {}, 第{}次", id, status, count);
        return new User().setStatus(status).setId(id).setUsername(serverPort);
    }

    public static void main(String[] args) {
        SpringApplication.run(UserApplication.class, args);
    }

}
